/**
 * 文件名称：  PageSeparateTap.java
 * 文件版权:  China Gowin Technologies Co., Ltd. Copyright 2007-2012,All rights reserved
 * 文件描述:  <描述>
 * 修改作者:  LiXiangDong
 * 修改时间:  2012-10-26
 * 跟踪单号:  <跟踪单号>
 * 修改单号:  <修改单号>
 * 修改内容:  <修改内容>
 */
package com.parasol.hcerp.common.page;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;

/**
 * 
 * <一句话功能简述>
 * <功能详细描述>
 * 
 * @author  LiXiangDong
 * @version V1.0, 2012-10-26
 */
public class PageSeparateTap extends SimpleTagSupport
{
    /**
     * 总页数<br>
     */
    private String totalPage = "";
    
    /**
     * 每页显示的记录数 <br>
     */
    private String pageSize = "";
    
    /**
     * 当前的页数<br>
     */
    private String currentPage = "";
    
    /**
     * 默认的选择页数<br>
     */
    private String selectPage = "10";
    
    /**
     * action链接<br>
     */
    private String actionName = "";
    
    private String methodName = "";
    
    /**
     * 表单名字<br>
     */
    private String formName = "";
    
    public static final int INITIAL_BUFFER = 16;
    
    public void doTag()
        throws JspException, IOException
    {
        JspWriter out = getJspContext().getOut();
        StringBuffer outStr = new StringBuffer(INITIAL_BUFFER);
        
        int totalPageInt = 0;
        
        if (totalPage != null && !"".equals(totalPage))
        {
            totalPageInt = Integer.parseInt(totalPage);
        }
        int currentPageInt = 0;
        
        if (currentPage != null && !"".equals(currentPage))
        {
            currentPageInt = Integer.parseInt(currentPage);
        }
        
        if (totalPageInt > 0)
        {
            // 生成首页按钮
            outStr.append("<span style='cursor:hand'");
            
            outStr.append(">");
            
            if (currentPageInt == 1)
            {
                outStr.append("<font color='#BBBBBB' size = '2'>");
            }
            else
            {
                outStr.append("<a href='javascript:goPage(1," + "\"" + actionName + "\",\"" + methodName + "\",\""
                    + formName + "\");'>");
            }
            
            outStr.append("第一页");
            
            if (currentPageInt == 1)
            {
                outStr.append("</font>");
            }
            else
            {
                outStr.append("</a>");
            }
            
            outStr.append("</span>&nbsp;");
            
            // 生成前一页按钮
            outStr.append("<span style='cursor:hand'>");
            
            if (currentPageInt == 1)
            {
                outStr.append("<font color='#BBBBBB' size = '2'>");
            }
            else
            {
                outStr.append("<a href='javascript:goPage(" + (currentPageInt - 1) + "," + "\"" + actionName + "\",\""
                    + methodName + "\",\"" + formName + "\")'>");
            }
            
            outStr.append("上一页");
            
            if (currentPageInt == 1)
            {
                outStr.append("</font>");
            }
            else
            {
                outStr.append("</a>");
            }
            
            outStr.append("</span>&nbsp;");
            
            outStr.append("<span style='cursor:hand'");
            
            outStr.append(">");
            
            if (currentPageInt == totalPageInt)
            {
                outStr.append("<font color='#BBBBBB' size = '2'>");
            }
            else
            {
                outStr.append("<a href='javascript:goPage(" + (currentPageInt + 1) + "," + "\"" + actionName + "\",\""
                    + methodName + "\",\"" + formName + "\")'>");
            }
            
            outStr.append("下一页");
            
            if (currentPageInt == totalPageInt)
            {
                outStr.append("</font>");
            }
            else
            {
                outStr.append("</a>");
            }
            
            outStr.append("</span>&nbsp;");
            
            outStr.append("<span style='cursor:hand'>");
            
            if (currentPageInt == 1)
            {
                outStr.append("</font>");
            }
            else
            {
                outStr.append("</a>");
            }
            
            if (currentPageInt == totalPageInt)
            {
                outStr.append("<font color='#BBBBBB' size = '2'>");
            }
            else
            {
                outStr.append("<a href='javascript:goPage(" + totalPageInt + "," + "\"" + actionName + "\",\""
                    + methodName + "\",\"" + formName + "\")'>");
            }
            
            outStr.append("末页");
            
            if (currentPageInt == totalPageInt)
            {
                outStr.append("</font>");
            }
            else
            {
                outStr.append("</a>");
            }
            outStr.append("</span>&nbsp;");
        }
        
        outStr.append("&nbsp;共&nbsp;<Font color='#1E90FF' size='2'>");
        outStr.append(totalPageInt);
        outStr.append("</Font>&nbsp;页");
        out.println(outStr.toString());
        
    }
    
    /**
     * @return Returns the currentPage.
     */
    public String getCurrentPage()
    {
        return currentPage;
    }
    
    /**
     * @param currentPage
     *            The currentPage to set.
     */
    public void setCurrentPage(String currentPage)
    {
        this.currentPage = currentPage;
    }
    
    /**
     * @return Returns the formName.
     */
    public String getFormName()
    {
        return formName;
    }
    
    /**
     * @param formName
     *            The formName to set.
     */
    public void setFormName(String formName)
    {
        this.formName = formName;
    }
    
    /**
     * @return Returns the pageSize.
     */
    public String getPageSize()
    {
        return pageSize;
    }
    
    /**
     * @param pageSize
     *            The pageSize to set.
     */
    public void setPageSize(String pageSize)
    {
        this.pageSize = pageSize;
    }
    
    /**
     * @return Returns the selectPage.
     */
    public String getSelectPage()
    {
        return selectPage;
    }
    
    /**
     * @param selectPage
     *            The selectPage to set.
     */
    public void setSelectPage(String selectPage)
    {
        this.selectPage = selectPage;
    }
    
    /**
     * @return Returns the totalPage.
     */
    public String getTotalPage()
    {
        return totalPage;
    }
    
    /**
     * @param totalPage
     *            The totalPage to set.
     */
    public void setTotalPage(String totalPage)
    {
        this.totalPage = totalPage;
    }
    
    /**
     * @return Returns the actionName.
     */
    public String getActionName()
    {
        return actionName;
    }
    
    /**
     * @param actionName the actionName to set
     */
    public void setActionName(String actionName)
    {
        this.actionName = actionName;
    }
    
    /**
     * @return Returns the methodName.
     */
    public String getMethodName()
    {
        return methodName;
    }
    
    /**
     * @param methodName the methodName to set
     */
    public void setMethodName(String methodName)
    {
        this.methodName = methodName;
    }
    
}
